package com.cosina.game.llk;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.cosina.game.llk.engine.Chart;
import com.cosina.game.llk.engine.FillContent;
import com.cosina.game.llk.engine.Hint;
import com.cosina.game.llk.engine.Tile;

public class LinkLink extends Activity implements OnClickListener{
	LLKView llk;
	private Button newGameButton,arrangeButton,hintButton,themeButton;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ThemeManager.init(this);
        resetContent();
    }

    public void resetContent(){
    	setContentView(R.layout.main);
    	llk = (LLKView)findViewById(R.id.llk);
    	Chart c = new Chart(FillContent.getRandom(12, 12, ThemeManager.imageCount-1));
        llk.setChart(c);
        
        newGameButton = (Button)findViewById(R.id.newGame);
        arrangeButton = (Button)findViewById(R.id.arrange);
        hintButton = (Button)findViewById(R.id.hint);
        themeButton = (Button)findViewById(R.id.theme);
        newGameButton.setOnClickListener(this);
        arrangeButton.setOnClickListener(this);
        hintButton.setOnClickListener(this);
        themeButton.setOnClickListener(this);
    }


	@Override
	public void onClick(View v) {
		if(v == newGameButton){
			resetContent();
		}
		else if(v == arrangeButton){
			 Chart chart = llk.getChart();
			 chart.reArrange();
			 llk.invalidate();
		}
		else if(v == hintButton){
			Tile[] hint = new Hint(llk.getChart()).findHint();
			llk.showHint(hint);
		}
		else if(v == themeButton){
			ThemeManager.changeTheme();
			llk.invalidate();
		}
	}

}